package com.tiantianyuegou.view;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.tiantianyuegou.R;

/**
 * 自定义输入dialog
 */
public class MyDialogEditText {

    Context context;
    DialogCallback dialogCallback;
    Dialog dialog;
    Button btn_cancel, btn_confirm;
    TextView text_dialog_title;
    EditText et_price, et_inventry;

    public MyDialogEditText(Context con) {
        this.context = con;
        dialog = new Dialog(context, R.style.myDialog);
        dialog.setContentView(R.layout.all_set_dialog);

        btn_cancel = (Button) dialog.findViewById(R.id.btn_cancel);
        btn_confirm = (Button) dialog.findViewById(R.id.btn_confirm);
        text_dialog_title = (TextView) dialog
                .findViewById(R.id.text_dialog_title);
        et_price = (EditText) dialog.findViewById(R.id.all_set_dialog_price);
        et_inventry = (EditText) dialog.findViewById(R.id.all_set_dialog_inventry);

        btn_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialogCallback.dialogOpt(et_price.getText().toString(), et_inventry.getText().toString());
                dismiss();
            }
        });
        btn_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    /**
     * 设定一个interfack接口,使mydialog可以處理activity定義的事情
     *
     */
    public interface DialogCallback {
         void dialogOpt(String price, String inventry);
    }

    public void setDialogCallback(DialogCallback dialogCallback) {
        this.dialogCallback = dialogCallback;
    }

    public void show() {
        dialog.show();
    }

    public void hide() {
        dialog.hide();
    }

    public void dismiss() {
        dialog.dismiss();
    }
}
